<template>
    <div class="inProcessing-box">
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
            <!-- 上传文件组件 -->
            <!-- <upLoadFiles :isShowDialog="isShowDialog" :currentOrderList="currentOrderList"></upLoadFiles> -->
            <upLoadFiles v-if="isShowDialog" :currentOrderList="currentOrderList" @close="close"></upLoadFiles>


            <van-list
                v-model="loading"
                :finished="finished"
                finished-text="没有更多数据"
                :immediate-check="false"
                :offset=50
                @load="onLoad">
                <template slot="default">
                    <showTmp 
                        v-for="(order, index) in orderList"
                        :key="order.id" 
                        :dataList="order"
                        :text="'处理订单'"
                        :describe="true"
                        :type="'number'"
                        :fieldList="[{ message: order.problem ? `技术问题：${order.problem}` : '技术问题：暂无' },
                            { message: order.plan ? `技术方案：${order.plan}` : '技术方案：暂无' }]"
                        @onTitle="getOrderDetail(order.id, order.status, index)"
                        style="margin-bottom: 5px">
                    </showTmp>
                </template>
            </van-list>
        </van-pull-refresh>
    </div>
</template>

<script>
import { Dialog } from 'vant'
import { isBottom } from '~/util/index.js'
import publicNum from '~/components/_publicNum'
import showTmp from '~/components/_orderShowTmp'
import upLoadFiles from '~/components/_upLoadFiles'

export default {
    data() {
        return {
            agent_id: 0,
            orderList: [],
            loading: false, // 上拉加载
            isLoading: false, // 下拉刷新
            finished: false,
            page: 1,
            nextNextPage: '',
            isShowDialog: false,
            fileList: [],
            order: 0,
            status: '',
            currentOrderList: null
        }
    },
    created() {
        this.getAgentName()
    },
    //缓存也会走的钩子
    deactivated(){
        this.$destroy(true);//销毁组件
    },
    methods: {
        // 获取agent name
        getAgentName() {
            this.$axios.get('/api/consumer/show').then(res => {
                if(res.status === 200) {
                    this.agent_id = res.data.data.id
                    this.getOrderList(res.data.data.id)
                }else{
                    that.$toast('请求错误');
                }
            })
        },
        // 获取order信息
        getOrderList(agent_id) {
            this.page = 1
            this.$axios.get('/api/order', { params: {
                status: `代理人撰写中,案件内审中,案件修改中,发明人确认定稿中,定稿文件上传中`,
                page: 1,
                agent_id: agent_id
            }}).then(res => {
                if(res.status === 200) {
                    if(res.data.page.total <= 15) {
                        this.finished = true
                    }else{
                        this.finished = false
                    }
                    this.orderList = res.data.data
                    this.isLoading = false;
                }else{
                   that.$toast('请求错误');
                }
            })
        },
        // // 处理订单
        // receipt(id, status, index) {
        //     this.currentOrderList = this.orderList[index]
        //     console.log(status, 'status')
        //     if(status === '发明人确认定稿中' || status === '定稿文件上传中'){
        //         this.isShowDialog = true
        //     }else{
        //         this.getOrderDetail(id)
        //     }
        // },
        getOrderDetail(id, status, index) {
            this.currentOrderList = this.orderList[index]
            if(status === '发明人确认定稿中' || status === '定稿文件上传中'){
                this.isShowDialog = true
            }else{
                this.$axios.get(`/api/order/${id}`).then(res => {
                    if(res.status === 200) {
                        this.$store.commit('getOrderDetailList', res.data.data)
                        this.$router.push(`/admin/order/detail2/${id}`)
                    }else{
                        that.$toast('请求错误');
                    }
                })
            }
        },
        onLoad() {
            setTimeout(() => {
                this.$axios.get('/api/order', { params: {
                    status: `代理人撰写中,案件内审中,案件修改中,发明人确认定稿中,定稿文件上传中`,
                    page: this.page + 1,
                    agent_id: this.agent_id
                }}).then(res => {
                    if(res.data.data.length > 0) {
                        this.page++
                        this.orderList.push(...res.data.data)
                        this.loading = false
                    }else{
                        this.loading = false
                        this.finished = true
                    }
                })
            }, 500);
        },
        onRefresh() {
            setTimeout(() => {
                this.getOrderList()
            }, 500);
        },
        close() {
            this.isShowDialog = false
        }
    },
    components: {
        publicNum,
        showTmp,
        upLoadFiles
    }
}
</script>

<style lang="less" scoped>
    .inProcessing-box{
        height: 100%;
        overflow: hidden;
        background-color: #eee;
        
        .van-swipe-cell{
            margin-bottom: 10px;
        }
        .van-swipe-cell__right{
            > button{
                height: 100%;
            }
        }
    }
</style>